package com.ray.util;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ray.exception.ServiceException;

public class ExceptionUtil {
	public static void ifNull(String str,String msg) throws ServiceException {
		if("".equals(str)||null==str) {
			throw new ServiceException(msg);
		}
	}
	/**
	 * 获取堆栈信息转换成字符类型
	 * @author Shensg
	 * @param level 
	 * @param throwable
	 * @param response 
	 * @param request 
	 * @return
	 */
	public static String getStackTrace(Throwable throwable) {
		StringWriter sw = new StringWriter();
		PrintWriter pw = new PrintWriter(sw);
		
		try {
			throwable.printStackTrace(pw);
			return sw.toString();
		} finally {
			try {
				if(pw!=null) pw.close();
				if (sw!=null) sw.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				System.out.println("ExceptionUtil.getStackTrace close stream fail");
			}
		}
	}
	

}
